"""
# @Time : 2023/8/3 21:42
# @Author : goose
"""
from selenium import webdriver
from selenium.webdriver.common.by import By
import time


# 获取浏览器驱动
class BrowserDriver:
    # 先初始化driver
    driver = None

    @classmethod
    def get_driver(cls):
        # 判断driver是否已创建，如果为None就需要去创建浏览器驱动对象，如果不为None，则直接返回driver
        if cls.driver is None:
            cls.driver = webdriver.Chrome()
            cls.driver.maximize_window()
            cls.driver.implicitly_wait(10)
        return cls.driver

    @classmethod
    def quit_driver(cls):
        # time.sleep(1)
        # 定义一个退出浏览器驱动对象的方法  浏览器驱动对象退出之后，还有一串效的字符串存在
        if cls.driver is not None:
            cls.get_driver().quit()
            cls.driver = None


# 定义获取弹出框消息的方法
class GetMsg:
    # 登录断言的方法
    @classmethod
    def get_msg(cls, path):
        time.sleep(2)
        # cls.driver = BrowserDriver()
        return BrowserDriver.get_driver().find_element(By.XPATH, path).text

# 获取时间戳
class PublicMethod:
    @classmethod
    def time_name(cls, name):
        time_name = name + str(time.time())[4:10]
        return time_name
